﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace Inspired.Euler
{
    /// <summary>
    /// 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
    /// 
    /// What is the sum of the digits of the number 2^1000?
    /// </summary>
    public static class Problem016
    {
        /// <summary>
        /// What is the sum of the digits of the number 2^1000?
        /// </summary>
        [EulerProblem(16, Title = "What is the sum of the digits of the number 2^1000?")]
        public static long Solve()
        {
            return(
                new BigInteger(Math.Pow(2, 1000))
                    .ToString().ToCharArray()
                    .Aggregate(0, (accum, item) => 
                        accum += (int)Char.GetNumericValue(item)));
        }
    }
}
